/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 06
 * Time: 17:31
 */
class Solution {
    public int addDigits(int num) {
        while(num != 0) {
            int sum = 0;
            while(num != 0) {
                sum += num % 10;
                num /= 10;
            }
            if(sum < 10) {
                return sum;
            }else {
                num = sum;
            }
        }
        return num;//0则不进入while循环，直接在这里返回
    }
}